var mongoose = require('mongoose');

/**
 * development 环境使用测试配置、production 环境使用沃云配置
 * @type {string}
 */
//开发环境外网
//const DB_URL = 'mongodb://47.92.65.152:27017';
//正式环境内网
const DB_URL = 'mongodb://root:lysy_123@dds-do2474ad1c2e32741.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32742.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32743.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32744.mongodb.zhangbei.rds.aliyuncs.com:3717/admin?replicaSet=mgset-500497314';
//正式环境外网
//const DB_URL = 'mongodb://root:lysy_123@dds-do2474ad1c2e32741315-pub.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32742710-pub.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32743572-pub.mongodb.zhangbei.rds.aliyuncs.com:3717,dds-do2474ad1c2e32744810-pub.mongodb.zhangbei.rds.aliyuncs.com:3717/admin?replicaSet=mgset-500497314';

mongoose.set('useCreateIndex', true);

// 连接数据库
mongoose.connect(DB_URL, {
    dbName: 'dig',
    useNewUrlParser: true,
    useUnifiedTopology: true
});

/**
 * 连接成功
 */
mongoose.connection.on('connected', function () {
    console.log('Mongoose connection open to ' + DB_URL);
});

/**
 * 连接异常
 */
mongoose.connection.on('error', function (err) {
    console.log('Mongoose connection error: ' + err);
});

/**
 * 连接断开
 */
mongoose.connection.on('disconnected', function () {
    console.log('Mongoose connection disconnected');
});

module.exports = mongoose;

